package org.jeecg.modules.online.cgform.utils;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Pattern;
import org.jeecg.common.util.oConvertUtils;
import org.jeecg.modules.online.cgform.entity.OnlCgformField;
import org.jeecg.modules.online.cgform.enums.CgformValidPatternEnum;

/* renamed from: org.jeecg.modules.online.cgform.d.j */
/* loaded from: hibernate-re-3.7.1-RC.jar:org/jeecg/modules/online/cgform/d/j.class */
public class OnlineImportValidator {

    /* renamed from: d */
    private Map<String, OnlCgformField> f338d;

    /* renamed from: e */
    private Map<String, OnlCgformField> f339e;

    /* renamed from: f */
    private static final String f340f = ",";

    /* renamed from: g */
    private static final String f341g = "第%s行校验信息:";

    /* renamed from: h */
    private static final String f342h = "总上传行数:%s,已导入行数:%s,错误行数:%s";

    /* renamed from: a */
    public static final String f343a = "error";

    /* renamed from: b */
    public static final String f344b = "tip";

    /* renamed from: c */
    public static final String f345c = "filePath";

    public OnlineImportValidator() {
    }

    public OnlineImportValidator(List<OnlCgformField> list) {
        this.f338d = new HashMap(5);
        this.f339e = new HashMap(5);
        for (OnlCgformField onlCgformField : list) {
            String fieldValidType = onlCgformField.getFieldValidType();
            if (fieldValidType != null && !"".equals(fieldValidType) && !CgformValidPatternEnum.ONLY.getType().equals(fieldValidType)) {
                if (CgformValidPatternEnum.NOTNULL.getType().equals(fieldValidType)) {
                    this.f339e.put(onlCgformField.getDbFieldName(), onlCgformField);
                } else {
                    this.f338d.put(onlCgformField.getDbFieldName(), onlCgformField);
                }
            }
            if (onlCgformField.getDbIsNull().intValue() == 0 || "1".equals(onlCgformField.getFieldMustInput())) {
                if (oConvertUtils.isEmpty(onlCgformField.getDbDefaultVal())) {
                    this.f339e.put(onlCgformField.getDbFieldName(), onlCgformField);
                }
            }
        }
    }

    /* renamed from: a */
    public String m281a(String str, int i) {
        OnlCgformField onlCgformField = null;
        String pattern;
        String msg;
        StringBuffer stringBuffer = new StringBuffer();
        JSONObject parseObject = JSON.parseObject(str);
        for (String str2 : this.f339e.keySet()) {
            String string = parseObject.getString(str2);
            OnlCgformField onlCgformField2 = this.f339e.get(str2);
            if (string == null || "".equals(string)) {
                stringBuffer.append(onlCgformField2.getDbFieldTxt() + CgformValidPatternEnum.NOTNULL.getMsg() + ",");
            }
        }
        for (String str3 : this.f338d.keySet()) {
            String string2 = parseObject.getString(str3);
            String fieldValidType = this.f338d.get(str3).getFieldValidType();
            if (string2 != null && !"".equals(string2)) {
                if (CgformValidPatternEnum.INTEGER.getType().equals(fieldValidType)) {
                    pattern = "^-?[1-9]\\d*$";
                    msg = "请输入整数";
                } else {
                    CgformValidPatternEnum patternInfoByType = CgformValidPatternEnum.getPatternInfoByType(fieldValidType);
                    if (patternInfoByType == null) {
                        pattern = fieldValidType;
                        msg = "校验【" + pattern + "】未通过";
                    } else {
                        pattern = patternInfoByType.getPattern();
                        msg = patternInfoByType.getMsg();
                    }
                }
                if (!Pattern.compile(pattern).matcher(string2).find()) {
                    stringBuffer.append(onlCgformField.getDbFieldTxt() + msg + ",");
                }
            }
        }
        if (stringBuffer.length() > 0) {
            return m280b(stringBuffer.toString(), i);
        }
        return null;
    }

    /* renamed from: b */
    public static String m280b(String str, int i) {
        return String.format(f341g, Integer.valueOf(i)) + str + "\r\n";
    }

    /* renamed from: a */
    public static String m282a(int i, int i2) {
        return String.format(f342h, Integer.valueOf(i), Integer.valueOf(i - i2), Integer.valueOf(i2));
    }
}
